import api from '../request'

// 计费方式数据类型定义
export interface BillingMethodData {
  id?: number
  propertyCompanyId: number
  feeType: string
  buildingTypeName?: string
  methodName: string
  methodType: number
  unitPrice?: number
  fixedAmount?: number
  tierConfig?: string
  description?: string
  status?: number
  sortOrder?: number
}

export interface BillingMethodQuery {
  propertyCompanyId?: number
  propertyCompanyIds?: number[]
  feeType?: string
  buildingTypeName?: string
  methodName?: string
  methodType?: number
  includeAllBuildingTypes?: boolean
  current?: number
  size?: number
}

export interface BillingMethodVO {
  id: number
  propertyCompanyId: number
  propertyCompanyName: string
  feeType: string
  feeTypeText: string
  buildingTypeName?: string
  buildingTypeDisplayText: string
  methodName: string
  methodType: number
  methodTypeText: string
  unitPrice?: number
  fixedAmount?: number
  tierConfig?: string
  description?: string
  status: number
  statusText: string
  sortOrder: number
  createBy: number
  createByName: string
  createTime: string
  updateTime: string
  remark?: string
}

// 计费方式API接口
export const billingMethodApi = {
  // 分页查询计费方式
  getBillingMethodPage: (params: BillingMethodQuery) => {
    return api.post('/api/property/billing-method/page', params)
  },

  // 根据物业公司ID和费用类型查询计费方式列表
  getBillingMethodList: (params: {
    propertyCompanyId: number
    feeType: string
    buildingTypeName?: string
  }) => {
    return api.get('/api/property/billing-method/list', { params })
  },

  // 根据物业公司ID列表和费用类型查询计费方式列表
  getBillingMethodListByMultiCompany: (params: {
    propertyCompanyIds: number[]
    feeType: string
    buildingTypeName?: string
  }) => {
    return api.post('/api/property/billing-method/list/multi-company', params)
  },

  // 根据ID查询计费方式详情
  getBillingMethodDetail: (id: number) => {
    return api.get(`/api/property/billing-method/${id}`)
  },

  // 创建计费方式
  createBillingMethod: (data: BillingMethodData) => {
    return api.post('/api/property/billing-method', data)
  },

  // 更新计费方式
  updateBillingMethod: (data: BillingMethodData) => {
    return api.put('/api/property/billing-method', data)
  },

  // 删除计费方式
  deleteBillingMethod: (id: number) => {
    return api.delete(`/api/property/billing-method/${id}`)
  },

  // 批量删除计费方式
  batchDeleteBillingMethods: (ids: number[]) => {
    return api.delete('/api/property/billing-method/batch', { data: ids })
  },

  // 根据建筑类型名称查询适用的计费方式
  getApplicableBillingMethods: (params: {
    propertyCompanyId: number
    feeType: string
    buildingTypeName: string
  }) => {
    return api.get('/api/property/billing-method/applicable', { params })
  }
}
